<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.model.Payment"%>

<c:choose>
	<c:when test="${null != actionBean.resultPayment}">

<div id="cancelPaymentViewDiv">

		<table id="paymentListTable">
				<tr>
					<td colspan="6">
						<table>				
							<tr>
								<td colspan="6" class="paymentHeader">
									<c:out value="${actionBean.resultPayment.paymentName}"/></td>
							</tr>
							<tr>
								<th>繳費帳號</th>
								<td><c:out value="${actionBean.resultPayment.virtualAccount}"/></td>
								<th>姓名</th>
								<td><c:out value="${actionBean.resultPayment.payerName}"/></td>
								<th>總金額</th>
								<td align="right"><fmt:formatNumber value="${actionBean.resultPayment.totalAmount}" pattern="##,###" /></td>
							</tr>
							<tr>
								<th colspan="6">繳費明細</th>
							</tr>
							<c:set var="old" value="${true}"/>
							<c:forEach items="${actionBean.resultPayment.paymentItems}" var="paymentItem" varStatus="rowstat1">
							<c:if test="${paymentItem.amount != 0 }">
								<c:if test="${old}"><tr></c:if>
									<th><c:out value="${paymentItem.itemName}"/></th>
									<td colspan="2" align="right"><fmt:formatNumber value="${paymentItem.amount}" pattern="##,###" /></td>
									<c:if test="${not old}"> </tr> </c:if>
								<c:set var="old" value="${not old }"/>
							</c:if>
							</c:forEach>
							<%//old == flase =>基數個，需要再補空白欄位與結束符號 %>
							<c:if test="${not old}"><th>&nbsp;</th><td colspan="2">&nbsp;</td></tr></c:if>
						</table>
					</td>
				</tr>
				<tr>				
			</tr>
		</table>
		
</div>
		
<div id="cancelPaymentsHiddenFormDiv" style="display: none; ">
	<stripes:form id="cancelPaymentsHiddenFrom" beanclass="com.feib.soeasy.action.Soez1016ActionBean" 
		method="post" onsubmit="javascript: return false;">			
		<input type="hidden" id="hidden2.qryPayment.paymentPk" name="qryPayment.paymentPk" value="<c:out value='${actionBean.resultPayment.paymentPk}'/>"/>
		<input type="hidden" id="hidden2.reason" name="reason"/>					
		<input type="hidden" id="method3" name="doPaymentsCanceledAction"/>
	</stripes:form>
</div>

<div id="cancelPaymentMsgDiv" style="display: none; ">
</div>
		
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$("#doCanceledPaymentBtn").click(function() {
				var reason = $('#reason').val();
				$('#hidden2\\.reason').val(reason);
				
				waitingDialog({});
				$.ajax({url : "<c:url value='/ajax/Soez1016.action'/>",
					async : false,
					type : 'POST',
					data : $("#cancelPaymentsHiddenFrom").serialize(),
					dataType : 'html',
					success : function(data, textStatus, XMLHttpRequest){
							$("#cancelPaymentViewDiv").hide();
							$("#cancelPaymentMsgDiv" ).html(data);
							$("#cancelPaymentMsgDiv").show();
						},
					error : function(XMLHttpRequest, textStatus, errorThrown){
						$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
						$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
						$("#ajaxErrorMessageDiv" ).dialog({  
							title:'系統錯誤' 
							,width: 600
							, resizable: false
							, modal: true
							, buttons: {
								Ok: function() {
									$( this ).dialog( "close" );
								}
							}
						});
						},
					complete: function(XMLHttpRequest, textStatus){
						closeWaitingDialog();
					}
				});
			});
			
		});
		//-->
		</script>

	</c:when>
	<c:otherwise>
			查無資料
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$( "#paymentsItemDiv" ).dialog( "destroy" );
			$( "#paymentsItemDiv" ).dialog({  title:'繳費單資料' ,width: 600, resizable: false, modal: true  });
		});
		//-->
		</script>
	</c:otherwise>
</c:choose>